/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package com.googlecode.javalearningproject.VEK_ME.GUI;

import com.googlecode.javalearningproject.VEK_ME.controllers.MainControllerCanvas;
import com.googlecode.javalearningproject.util.FileGetter;
import javax.microedition.lcdui.Graphics;
import javax.microedition.lcdui.Image;
import javax.microedition.lcdui.game.GameCanvas;

/**
 *
 * @author Administrator
 */
public class MainGraphicsCanvas extends GameCanvas{
    
    private UI_LayerManager layerManager;
    private BackgroundLayer backgroundLayer;
    private POILayer poiLayer;
    private Image backgroundImage;
    private MainControllerCanvas inputController;
    private int totalWidth;
    private int totalHeight;
    public final int SCREEN_WIDTH = getWidth();
    public final int SCREEN_HEIGHT = getHeight();
    
    
    public MainGraphicsCanvas()
    {
        super(false); //does not disable the selection keys, but not other keys
        Image background = FileGetter.getImage("../VEK_ME/Data/images/background/kort_beta3_medium.gif");
        backgroundImage = background;
        backgroundLayer = new BackgroundLayer(10, 10, background, 100, 200);
        layerManager = new UI_LayerManager(backgroundLayer);
        
        totalWidth = background.getWidth(); // change later
        totalHeight = background.getHeight(); // change later
        
        inputController = new MainControllerCanvas(SCREEN_WIDTH, SCREEN_HEIGHT, totalWidth, totalHeight);

    }
    
    public void paintCanvas()
    {
        Graphics g = getGraphics();
        
        layerManager.paint(g, 0, 0);
        flushGraphics();
    }
    
    protected void keyPressed(int keycode)
    {
        inputController.respondToInput(this, keycode, layerManager.getViewPosX(), layerManager.getViewPosY());
        //System.out.println("current position: " + layerManager.getViewPosX() 
        //        + "," + layerManager.getViewPosY() + " totals: " + totalWidth
        //        + "," + totalHeight + " screen size: " + SCREEN_WIDTH + "," + SCREEN_HEIGHT);
        
    }
    
    public void moveView(int x, int y)
    {
        layerManager.setViewPos(x, y, SCREEN_WIDTH, SCREEN_HEIGHT);
        paintCanvas();
    }
    

    
    

}
